home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Views / Canvas Loops / CanvasLoopBase.cp < prev    next >
Text File  |  2000-06-23  |  2KB  |  108 lines

  1. // CanvasLoopBase.cp
  2.  
  3. #ifndef CanvasLoopBase_h
  4. #include "CanvasLoopBase.h"
  5. #endif
  6. #ifndef DrawsSpontaneously_h
  7. #include "DrawsSpontaneously.h"
  8. #endif
  9. #ifndef Pane_h
  10. #include "Pane.h"
  11. #endif
  12. #ifndef ConstStackLoop_h
  13. #include "ConstStackLoop.h"
  14. #endif
  15.  
  16. void CanvasLoopBase::FindFirstPath( const DrawsSpontaneously *position )
  17.   {
  18.     while ( position != 0 && !position->panes.IsEmpty() )
  19.       {
  20.         const Pane *up = *position->panes.First();
  21.         Assert( up != 0 );
  22.         path.Push( up );
  23.         position = up->Parent();
  24.       }
  25.   }
  26.  
  27. void CanvasLoopBase::AdvancePath()
  28.   {
  29.     while ( !path.IsEmpty() )
  30.       {
  31.         const Pane *top = path.Top();
  32.         Assert( top != 0 );
  33.     
  34.         if ( top->viewLink.Next() != 0 )
  35.           {
  36.             const Pane *next = *top->viewLink.Next();
  37.             path.Top() = next;
  38.             FindFirstPath( next->Parent() );
  39.             return;
  40.           }
  41.  
  42.         path.Pop();
  43.       }
  44.   }
  45.  
  46. void CanvasLoopBase::AdvancePathUntilReachingPort()
  47.   {
  48.     while ( !path.IsEmpty() && path.Top()->Parent() != 0 )
  49.         AdvancePath();
  50.   }
  51.  
  52. void CanvasLoopBase::FindFirstPathToPort( const DrawsSpontaneously *start )
  53.   {
  54.     FindFirstPath( start );
  55.     AdvancePathUntilReachingPort();
  56.   }
  57.  
  58. void CanvasLoopBase::AdvancePathToPort()
  59.   {
  60.     AdvancePath();
  61.     AdvancePathUntilReachingPort();
  62.   }
  63.  
  64. void CanvasLoopBase::BuildCanvas()
  65.   {
  66.     Assert( !path.IsEmpty() );
  67.     Assert( path.Top() != 0 );
  68.     Assert( path.Top()->Parent() == 0 );
  69.     
  70.     for ( ConstStackLoop<const Pane *> pathPosition( path );
  71.             pathPosition.Unfinished();
  72.             pathPosition++ )
  73.       {
  74.         Assert( *pathPosition != 0 );
  75.         (*pathPosition)->Adjust( canvas );
  76.         
  77.         if ( !canvas.Visible() )
  78.             break;
  79.       }
  80.   }
  81.  
  82. void CanvasLoopBase::AdvanceUntilVisible()
  83.   {
  84.     for ( ; Unfinished(); AdvancePathToPort() )
  85.       {
  86.         BuildCanvas();
  87.     
  88.         if ( canvas.Visible() )
  89.             return;
  90.  
  91.         canvas.Clear();
  92.       }
  93.   }
  94.  
  95. CanvasLoopBase::CanvasLoopBase( const DrawsSpontaneously& view )
  96.   {
  97.     FindFirstPathToPort( &view );
  98.     AdvanceUntilVisible();
  99.   }
  100.  
  101. void CanvasLoopBase::operator++()
  102.   {
  103.     Assert( Unfinished() );
  104.     canvas.Clear();
  105.     AdvancePathToPort();
  106.     AdvanceUntilVisible();
  107.   }
  108.